package sajat.onlab;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class PoiListAdapter extends BaseAdapter{
	
	private ArrayList<Poi> pois;

	public PoiListAdapter(ArrayList<Poi> pois){
		this.pois = pois;
	}
	
	@Override
	public int getCount() {
		return pois.size();
	}

	@Override
	public Object getItem(int arg0) {
		return pois.get(arg0);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		final Poi poi = pois.get(position);
		
		if(convertView == null){
			LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.poirowlayout, null);
		}
		
		TextView name = (TextView) convertView.findViewById(R.id.name);
		TextView rated = (TextView) convertView.findViewById(R.id.rating);
		
		name.setText(poi.getName());
		rated.setText("Rated: ");
		for (int i=0; i<poi.getRate(); i++) {
			rated.append("*");
		}
		rated.append(" ("+poi.getRate()+"/5)");
		
		return convertView;
	}

}
